import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '学生成绩管理系统', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/test',
    component: Layout,
    redirect: 'noRedirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/test/index'),
        name: 'test',
        meta: { title: '学生信息', icon: 'theme' }
      }
    ]
  },
  // 成绩
  {
    path: '/score',
    component: Layout,
    redirect: 'noRedirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/score/index'),
        name: 'score',
        meta: { title: '学生成绩', icon: 'el-icon-s-custom' }
      }
    ]
  },
  // 信息查询和修改
  {
    path: '/FindAndUpdate',
    component: Layout,
    redirect: 'noRedirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/FindAndUpdate/index'),
        name: 'FindAndUpdate',
        meta: { title: '信息查询和修改', icon: 'el-icon-search' }
      }
    ]
  },
  // 满意度建议功能
  {
    path: '/satisfaction',
    component: Layout,
    redirect: 'noRedirect',
    children: [
      {
        path: 'index',
        component: () => import('@/views/satisfaction/index'),
        name: 'FindAndUpdate',
        meta: { title: '满意度建议', icon: 'el-icon-star-off' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
